package com.sasis.util;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;

import org.apache.commons.beanutils.PropertyUtilsBean;

public class PrintUtil {

	public static void printBean(Object bean) {
		PropertyUtilsBean pu = new PropertyUtilsBean();
		PropertyDescriptor origDescriptors[] = pu.getPropertyDescriptors(bean);
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < origDescriptors.length; i++) {
			String name = origDescriptors[i].getName();

			Object value;
			try {
				if(!"class".equals(name) && pu.isReadable(bean, name)){
					value = pu.getSimpleProperty(bean, name);
					sb.append("name: " + name + "; value: " + value);
					sb.append("\n");
				}
			} catch (IllegalAccessException e) {
				//System.out.println(e.getMessage());
				//e.printStackTrace();
			} catch (InvocationTargetException e) {
				//System.out.println(e.getMessage());
				//e.printStackTrace();
			} catch (NoSuchMethodException e) {
				//System.out.println(e.getMessage());
				//e.printStackTrace();
			}
		}
		System.out.println(sb.toString());
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

	}

}
